package com.dmx.cep.util;

public class TextFilter {
	public static String filter(String content) {
		StringBuilder sb = new StringBuilder();
		char highSurrogate = 0;
		for (char c : content.toCharArray()) {
			if(c=='\n'||c=='\r'){
				sb.append(c);
				continue;
			}
			
			if (isIgnorable(c)) {
				highSurrogate = 0;
			} else if (Character.isHighSurrogate(c)) {
				// save high surrogate char
				highSurrogate = c;
			} else if (Character.isLowSurrogate(c)) {
				if (highSurrogate != 0) {
					// save surrogate pair
					sb.append(highSurrogate);
					sb.append(c);
					highSurrogate = 0;
				}
			} else {
				highSurrogate = 0;
				sb.append(c);
			}
		}
		return sb.toString();
	}

	private static boolean isIgnorable(char c) {
		// skip ISO control char
		return Character.isISOControl(c) || c == '\uFFFD';
	}
	
	public static void main(String[] args){
		String s="";
	}
}
